home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / pclearn5.arc / PCL.ARC / BATCH.TUT < prev    next >
Text File  |  1991-02-16  |  33KB  |  717 lines

  1.  
  2.        ████████████████████████████████████████████████████████████████ 
  3.  
  4.               BATCH FILES FOR EFFICIENCY - GETTING THE WORK DONE 
  5.  
  6.        ████████████████████████████████████████████████████████████████ 
  7.  
  8.        A batch file contains within it a series of DOS commands in a 
  9.        list. The commands may be either DOS other special batch 
  10.        commands you wish the computer to perform in sequence. These 
  11.        operations can be DOS operations (e.g., format a disk, display 
  12.        the date and time, etc) or other operations which load or start 
  13.        another program. 
  14.        
  15.        Another way to think about a batch file is that it takes the 
  16.        place of your keyboard and issues commands one after another 
  17.        until it reaches a conclusion. Batch files operate line by line 
  18.        and are read directly from the disk which makes them a little 
  19.        slow, but nevertheless useful and extremely flexible. 
  20.        
  21.        Batch files can even prepare a menu system for your hard drive 
  22.        and spare you the expense of buying a menu program from commercial 
  23.        sources. Working with batch files means you are programming in 
  24.        the most literal sense! 
  25.     
  26.        Each line of a batch file contains one instruction or operation 
  27.        which the computer is to perform. Below is a listing for a very 
  28.        simple batch file example. Don't worry about understanding it 
  29.        just yet, simply note that each instruction is a DOS command on 
  30.        a separate line . . .  
  31.  
  32.           EXAMPLE BATCH FILE            EXPLANATION
  33.                |                               |
  34.               date                         date displayed
  35.               time                         time displayed
  36.               ver                          DOS version displayed
  37.               dir a:/p                     directory of a: floppy 
  38.                                            displayed with a pause
  39.  
  40.        The primary use of batch files is to automate sequences or 
  41.        instructions which you use frequently. A batch file always has 
  42.        the extension BAT. Example:  hello.bat 
  43.  
  44.        Each line in the batch file is a separate command and is 
  45.        performed AS IF you had typed in the command from your keyboard 
  46.        at the DOS prompt! In addition to the usual DOS commands, batch 
  47.        files can also contain special batch commands which allow you to 
  48.        build small programs. We will talk about the special batch 
  49.        commands a little later in this tutorial. Branching (selecting 
  50.        various directions or choices) and iteration (repetitions of a 
  51.        command) are allowed within the framework of these unique batch 
  52.        commands. In addition, batch files may have special parameters 
  53.        or inputs passed to them at the time you run the batch file from 
  54.        the DOS command line or prompt. Batch files are POWERFUL and can 
  55.        control many operations! They are also fun and easy to try.
  56.  
  57.        A batch file is run or started by typing the file name without 
  58.        the extension. This of course applies to all files ending with 
  59.        file extensions BAT, EXE or COM. 
  60.  
  61.        Example: a>hello   Then pressing enter or return key starts the 
  62.        batch file   hello.bat
  63.  
  64.        Example: c>whoops  starts the file whoops.exe
  65.  
  66.        To terminate or stop any batch file in progress issue the break 
  67.        command which uses the two key combination CONTROL-BREAK  (hold 
  68.        down the control CTRL key then press the break key) or  
  69.        CONTROL-SCROLL LOCK. 
  70.  
  71.        Let's prepare a batch file: 
  72.  
  73.        First make sure you have a formatted disk in your disk drive and 
  74.        DOS is displaying a DOS prompt such as a>. We will be using the 
  75.        command COPY CON (copy data from the CONsole) command. Note that 
  76.        any ASCII (plain english) text word processor or even EDLIN on 
  77.        your DOS disk can be used to prepare a batch file; COPY CON is 
  78.        only one of several alternatives. You can use either upper or 
  79.        lower case to prepare batch files (capitals or small letters.) 
  80.  
  81.        Type the following list when you have a DOS prompt such as a> 
  82.        and a blank formatted floppy disk in the drive to accept the batch 
  83.        file. 
  84.  
  85.        copy con 1.bat         (press enter)   (cursor skips to new line)
  86.        echo Hello there        (press enter)
  87.        ver                    (press enter)
  88.        date                   (press enter)
  89.        dir/p                  (press enter)
  90.        ^Z                     (press F6 OR hold control AND Z, 
  91.                                then press enter)
  92.  
  93.        When done you'll have prepared a batch file of DOS commands 
  94.        named 1.bat. This small file will print "hello there" then type 
  95.        the DOS version in use then display date and finally produce a 
  96.        directory listing and pause after each screenful. At this point 
  97.        the batch file ends and returns you to DOS. In the first line we 
  98.        use COPY CON to begin to prepare a batch file named 1.bat. In 
  99.        the last line the ^Z means end of batch file preparation - exit 
  100.        back to DOS. To run or execute the batch file since its name is 
  101.        1.bat, just type  1  (then press enter key) at the DOS prompt. 
  102.  
  103.        Another example batch file for you to try: 
  104.  
  105.        copy con f.bat                                    (press enter)
  106.        cls                                               (press enter)
  107.        pause                                             (press enter)
  108.        format b:                                         (press enter)
  109.        rem all done                                      (press enter)
  110.        ^Z  (press F6)                           then     (press enter)       
  111.  
  112.        This batch file (activated by typing f then enter) will clear 
  113.        the screen then prepare to format a blank disk in b: drive - you 
  114.        MUST have FORMAT.COM on the same disk as this batch file - 
  115.        remember that format is an EXTERNAL command. After the batch 
  116.        file has formatted the disk it prints "all done" on the screen. 
  117.        
  118.        Ctrl-Break key combination will halt the batch file operation
  119.        if you wish!.
  120.  
  121.        The next batch file might be used to backup wordprocessing data 
  122.        files which end in the file extension TXT (such as ACCOUNTS.TXT) 
  123.        from a source disk in the a: floppy drive to the b: floppy 
  124.        drive. You could name it B.BAT and when you need to backup 
  125.        simply put the master data disk in the a: drive and the backup 
  126.        disk in the b: drive and type B at the DOS prompt. We've omitted 
  127.        the copy con command at the top of the file and the ^Z at the 
  128.        end since you already know how to start and end a batch file. 
  129.  
  130.         REM This batch file backs up files ending in TXT to backup disk
  131.         ECHO READY TO BACKUP. SOURCE DISK IN A: DRIVE, TARGET IN B: ?
  132.         PAUSE                                                                 
  133.         COPY A:*.TXT B:                                                        
  134.         REM All done!                                                          
  135.  
  136.        One batch file can start or call another, but the original batch 
  137.        file cannot be returned to - you must continue on within the 
  138.        second batch file. 
  139.  
  140.        If a batch file contains a typing or syntax error in any of its 
  141.        commands, the computer will stop execution at that point and 
  142.        return you to DOS. DOS remembers which disk contains the batch 
  143.        file and the drive it was in. If you remove the original disk, 
  144.        DOS will ask you to replace it so it can finish executing the 
  145.        batch file. Batch files execute one step at a time from the disk 
  146.        and NOT from RAM memory. This disk-based nature of batch files 
  147.        make them a little slow, but they get the work done eventually. 
  148.  
  149.        Special batch file compiler utilities exist which speed 
  150.        execution of batch files. Contact the author of PC-LEARN if you 
  151.        are curious and want to make your batch files fly!
  152.  
  153.        A superlative book on batch files you might wish to investigate 
  154.        is MOS-DOS Batch File programming by Ronny Richardson, 1988,
  155.        Wincrest Books.
  156.  
  157.        Remember the VDISK command in our second DOS tutorial? Many DOS 
  158.        experts put commonly used batch files in the virtual or RAM disk 
  159.        where a batch file really flies! This is one trick which can 
  160.        turbocharge your batch file operations. Instead of executing in
  161.        slow fashion from a disk drive, the batch file is forced to run 
  162.        from a speed ramdisk!
  163.  
  164.        ████████████████████████████████████████████████████████████████ 
  165.  
  166.           AUTOEXEC.BAT FILE BASICS - THE WAKEUP CALL TO YOUR COMPUTER 
  167.  
  168.        ████████████████████████████████████████████████████████████████ 
  169.  
  170.        The AUTOEXEC.BAT file starts your computer exactly the way you 
  171.        want. It allows you to customize the machine to your liking as 
  172.        the computer comes to life. You can cause the AUTOEXEC.BAT file 
  173.        to print a startup menu of choices, load one particular program, 
  174.        execute another batch file or other useful tasks. The 
  175.        AUTOEXEC.BAT file is the first file DOS runs after loading 
  176.        itself and configuring the computer. The AUTOEXEC.BAT file must 
  177.        be on the same disk as DOS when the computer starts. 
  178.  
  179.        The AUTOEXEC.BAT file is a special batch file which MUST be 
  180.        placed in the main or root directory of a disk to function 
  181.        properly. 
  182.  
  183.        An AUTOEXEC.BAT file can always be modified, enlarged, edited, 
  184.        or deleted later as you wish. Sometimes it is useful to have 
  185.        several AUTOEXEC.BAT files. Each on a different startup disk to 
  186.        operate different programs! An AUTOEXEC.BAT file (like all BAT 
  187.        or batch files) can be modified with any common word processor. 
  188.        You don't have to use the copy con facility each time! DOS EDLIN 
  189.        line editing word processor will also do. EDLIN is covered in
  190.        your DOS manual.
  191.  
  192.        Make sure you have a formatted disk in your disk drive and DOS 
  193.        is displaying the usual DOS prompt when you construct a batch 
  194.        file. Make sure you do not accidentally over-write or destroy 
  195.        your current AUTOEXEC.BAT file! If necessary, rename your 
  196.        current AUTOEXEC.BAT file (using the rename or REN command)
  197.        and make a new file while saving the old one "just in case."
  198.        Never edit on your original DOS disk, work on a copy!
  199.  
  200.        Examine the next batch file preparation sequence: 
  201.  
  202.        copy con AUTOEXEC.BAT              (press enter)
  203.        123                                (press enter)
  204.        ^Z                                 (press enter)
  205.  
  206.        This means (first line) create a file named AUTOEXEC.BAT as 
  207.        typed from the keyboard or con (console). The (second line) 
  208.        start program named 123. Final line end of batch file 
  209.        preparation - stash it on the disk. 
  210.  
  211.        When finished you'll see a file named AUTOEXEC.BAT on your 
  212.        directory listing screen which contains automatic startup 
  213.        instructions. If this file were placed on your main DOS disk it 
  214.        would try to start a program such as 123.EXE if such a program 
  215.        existed there. 
  216.  
  217.        You can also start the AUTOEXEC.BAT by typing autoexec and then 
  218.        pressing enter. To take a "peek" at the contents of an 
  219.        AUTOEXEC.BAT file (or any bat file) simply use the type command. 
  220.  
  221.        Example: c>type AUTOEXEC.BAT   (shows contents on your screen)
  222.        Example: a>type b:AUTOEXEC.BAT 
  223.  
  224.        Here is another AUTOEXEC.BAT file, this time from a hard drive 
  225.        startup sequence; it provides a higher degree of control and 
  226.        direction that a computer user might need for hard drive 
  227.        customization. 
  228.  
  229.        copy con AUTOEXEC.BAT                             (press enter)
  230.        path \dos;\reflex;\wp;\util;\doc;\nor;\bat        (press enter)
  231.        prompt $P$G                                       (press enter)
  232.        cpu n                                             (press enter)
  233.        verify on                                         (press enter)
  234.        blank                                             (press enter)
  235.        mode bw80,r                                       (press enter)
  236.        dispclk                                           (press enter)
  237.        type menu                                         (press enter)
  238.        ^Z           (press F6 OR hold control AND Z, then press enter)
  239.  
  240.        Let's examine this more complicated AUTOEXEC.BAT file in greater 
  241.        detail: 
  242.  
  243.        The first line after "copy con AUTOEXEC.BAT" establishes a path 
  244.        command to help DOS search every subdirectory on the hard disk 
  245.        (you don't have to switch around to different areas of the disk,
  246.        DOS will search around for you since it now knows the various 
  247.        "paths" to take.) 
  248.  
  249.        The second line alters the cursor prompt to tell you your 
  250.        location and subdirectory. 
  251.  
  252.        The third line is a reference to the speed the computer will 
  253.        operate at and is a unique command to a particular brand of 
  254.        machine (cpu n means start the central processing unit chip at 
  255.        normal speed.) Cpu is really CPU.COM, an external file which 
  256.        sets the computer's processing speed. 
  257.  
  258.        The fourth line turns on the verify function for file copying. 
  259.  
  260.        The next line instructs the DOS mode function to switch to black 
  261.        and white display, 80 columns wide and shift one column to the 
  262.        right for alignment. 
  263.  
  264.        Next we ask DOS to tell us the time and date. 
  265.   
  266.        A final line instructs DOS to type to the screen a file 
  267.        containing an ASCII test file prepared with an ordinary word
  268.        processor the menu for the monitor to display. Menu probably 
  269.        gives us choices of programs to one and thus calls other 
  270.        batch files such as 1.bat, 2.bat and so on. 
  271.  
  272.        The ^Z of course ends the file and instructs DOS to store the 
  273.        file away for future use on the disk. 
  274.  
  275.        ████████████████████████████████████████████████████████████████ 
  276.  
  277.                           BATCH FILE COMMANDS AND USE 
  278.  
  279.        ████████████████████████████████████████████████████████████████ 
  280.  
  281.        In addition to the normal DOS commands, batch files have their 
  282.        own special subcommands. These commands are: 
  283.  
  284.        ███ REM ███ The rem command sends a message to the screen or 
  285.        simply to document or note a part of a batch file's operation. 
  286.        You should use REM extensively to document long detailed batch 
  287.        files so you can revise things and locate portions of the 
  288.        program if you decide to change the batch file later. Remarks 
  289.        can be up to 123 characters long. REM does not cause any 
  290.        operation, it merely documents what you want to say or do.          
  291.  
  292.        Example: c>REM this is the location of menu operations 
  293.  
  294.        In DOS 2.0 the REM command could be replaced with a period or 
  295.        dot, but this is not true in DOS 3.0 and above. 
  296.  
  297.        Example:  c>. this is the location of menu operations 
  298.  
  299.        ███ PAUSE ███ Stops batch file execution on a temporary basis 
  300.        until you press a key. Thus you can pause a batch file and do 
  301.        some operation (perhaps changing a floppy disk) and then 
  302.        continue when you strike a key. 
  303.  
  304.        Example: b>PAUSE  (no optional message included here) 
  305.        Example: b>PAUSE This is an optional message, pardner! 
  306.  
  307.        ███ ECHO ███ Turns display listing of commands on/off. It can 
  308.        also send a message to the screen. It is frequently turned off 
  309.        to remove excessive screen messages. Normally, with ECHO on, 
  310.        screen messages are sent to the screen which can be distracting. 
  311.        To suppress them use the first example. To restart the messages 
  312.        use the second example. To add a message with the ECHO command 
  313.        see example three. REM or remark command can also send a message 
  314.        to the screen but NOT with ECHO turned off! 
  315.  
  316.        Example:   a>ECHO OFF 
  317.        Example:   a>ECHO ON 
  318.        Example:   a>ECHO It's raining cats, dogs and PC's. 
  319.  
  320.        ███ PARAMETERS AND MARKERS ████  This is NOT a batch file 
  321.        command like ECHO or PAUSE. 
  322.  
  323.        Instead parameters are additional pieces of information or 
  324.        "modifiers" which follow DOS commands. 
  325.  
  326.        Example:   c>format b:/s     
  327.  
  328.        In the above, format is the command while b: and /s are the 
  329.        parameters. Parameters modify the basic operation of a DOS 
  330.        command but are not required by the command to operate. A batch 
  331.        file can also accept parameters such as a word, filename, 
  332.        symbol, drive letter or any useful character or group of 
  333.        characters! 
  334.  
  335.        Markers placed inside the batch file listing signify which 
  336.        parameter goes where. Markers are made from a percent sign (%) 
  337.        and a single digit between 0 and 9 for a total of ten markers 
  338.        available (remember, zero is a number too.) Here are the ten 
  339.        markers: 
  340.  
  341.        %0    %1    %2    %3    %4    %5    %6    %7    %8    %9 
  342.  
  343.        Let's use an example. Pretend that DOLITTLE.BAT is on your 
  344.        floppy. Within its listing of commands there might be this 
  345.        single line: 
  346.  
  347.        ECHO %0 %1 %2      (ECHO shows messages on the monitor) 
  348.  
  349.        If at the DOS prompt you typed:  
  350.        
  351.        b>DOLITTLE fancy pants  (then press enter) 
  352.  
  353.        Your screen would show the following:    b>ECHO DOLITTLE fancy 
  354.        pants. 
  355.  
  356.        In this case, %0 has taken on the value at the start of the DOS 
  357.        command which is the first word "DOLITTLE". Meanwhile %1 has 
  358.        become "fancy" and %2 is now pants. 
  359.  
  360.        Looking at this another way: 
  361.  
  362.                         DOLITTLE   fancy  pants 
  363.                          |          |       | 
  364.                  ECHO    %0         %1      %2    
  365.  
  366.        Let's try an example. Pretend you had a large file of word
  367.        processing accounts for bills you have to pay from time to 
  368.        time. 
  369.  
  370.        You need to look up bills or amounts in the file accounts.txt 
  371.        which is in plain ASCII (english) text from your word processor. 
  372.        The DOS FIND utility can search large files for specific words, 
  373.        strings or characters. The general format for the FIND command 
  374.        is: FIND "text" filename. FIND is located in the file FIND.COM
  375.        on your DOS disk and must be present with the batch file to be
  376.        used.
  377.  
  378.        A simple batch file possibly named GET.BAT could do this: 
  379.  
  380.        ECHO searching for data . . . . 
  381.        FIND "%1" %2 
  382.        ECHO Finished, boss 
  383.  
  384.        Start the batch file get.bat with search data like this: 
  385.  
  386.        a>get grocery accounts.txt    (first word starts get.bat, second 
  387.        word is the item to search for, third item is the file to 
  388.        search.) 
  389.        
  390.        As a result, you will get a report of the line where the word 
  391.        "grocery" is found and any other data on the same line. This 
  392.        could also be used to search a telephone list or list of employee 
  393.        names and addresses. Pretty powerful idea for such a short
  394.        batch file!
  395.  
  396.        ███ GOTO ███  Jumps to a labeled set of commands within the 
  397.        batch file. The general format for the command is    GOTO LABEL 
  398.        where LABEL is a line in the batch file which must start with a 
  399.        colon (:) followed by a name up to eight characters long. 
  400.  
  401.        A simple, but useless batch file illustrates the GOTO command by 
  402.        looping around in circles doing the same task endlessly.            
  403.                                                             
  404.        Example listing for batch file: 
  405.  
  406.        :kitty 
  407.        REM watch this fill your screen over and over, folks 
  408.        GOTO kitty 
  409.  
  410.        This batch file will continue to print the remark line over and 
  411.        over since it always returns to the start. Tap Ctrl-Break to 
  412.        stop this silliness. The true usefulness of the GOTO command is 
  413.        best understood by allowing the GOTO within a batch file to 
  414.        transfer control elsewhere within its listing rather than to the 
  415.        line immediately next in sequence. You can thus cause one thing
  416.        to happen (depending on a condition) or a different thing to
  417.        happen: choices and different outcomes!
  418.  
  419.        ███ IF ███  Allows conditional operation of a command. This is a 
  420.        fancy way of saying you can cause a batch file to make decisions 
  421.        based on a logical condition or input then do something. The 
  422.        usual syntax of the IF command is IF CONDITION COMMAND. Let's 
  423.        take this apart and examine the concept. 
  424.  
  425.        In the situation IF CONDITION COMMAND: 
  426.  
  427.        COMMAND is any normal DOS or batch file command and CONDITION is 
  428.        one of three possible tests that yield true or false.         
  429.  
  430.        Example:  IF %1==w GOTO dog        (we'll explain this in a bit) 
  431.        Example:  IF %3 == 80 MODE BW80    (we'll explain this in a bit) 
  432.  
  433.        The three possible tests are: 
  434.  
  435.        1. The ERRORLEVEL condition (i.e., a specific number is found). 
  436.        2. The STRING COMPARISON. (i.e., two strings are equivalent or 
  437.        not.) 
  438.        3. The FILE EXISTENCE condition. (i.e., if a file exists or not.) 
  439.  
  440.        In true full-featured programming languages many other logical 
  441.        tests might be allowed, but for batch files these are these the 
  442.        only three tests. Let's examine the three more closely. Then 
  443.        illustrate with an example. 
  444.  
  445.        1. ERRORLEVEL is a number which tells DOS whether the last 
  446.        program run was successful. If so the errorlevel is zero (0) 
  447.        anything else above zero means unsuccessful. 
  448.  
  449.        2. STRING COMPARISON, the second conditional test, is always 
  450.        indicated in a batch file by double equals signs (==). A test is 
  451.        symbolically shown by the condition IF string1 == string2. 
  452.        Frequently used with parameters or markers such as:  IF %3 == 80 
  453.        MODE BW80. 
  454.  
  455.        3. In the final and third conditional test, FILE EXISTENCE, the 
  456.        usual format is IF EXIST d:filename.ext. which checks for a 
  457.        certain file on a certain drive. You can thus check for a 
  458.        certain disk or file before continuing the batch file process. 
  459.        Pathnames are not allowed (d:\slip\and\slide). 
  460.  
  461.        Let's try a batch file example to illustrate the use of STRING 
  462.        COMPARISONS to make a choice in how the batch file does its 
  463.        work. Pretend you have two programs. One is a word processor 
  464.        whose command to start is WORD and the other is a spreadsheet 
  465.        whose command is LOTUS to start. 
  466.  
  467.        If we prepared a simple batch file called 1.bat whose listing is 
  468.        below, we could start one or the other program by using either 
  469.        the command:  
  470.  
  471.        a>1 w (to start the word processor  OR   
  472.        a>1 s  (to start the spreadsheet). 
  473.  
  474.        The remarks (REM) in the example below give you a clue to the 
  475.        construction of the batch file program but are not themselves 
  476.        commands. The end result of this batch file is a saving of 
  477.        keystrokes for two programs we might start often. You'll notice 
  478.        we have omitted the copy con at the beginning and ^Z at the end 
  479.        since you already know from previous examples how to start and 
  480.        stop batch file preparation using those steps. The REM (remarks) 
  481.        in this batch file are optional and could be omitted from the 
  482.        real thing 
  483.       
  484.        REM This batch file selects one of two choices based on input
  485.        REM The next line turns off the screen echo to avoid screen clutter
  486.        ECHO OFF
  487.        REM Begin test for one of two choices
  488.        REM %1 in the next lines are markers for "w" or "s" from keyboard 
  489.        IF %1==w GOTO dog
  490.        IF %1==s GOTO cat
  491.        REM Next line forces goto end if no match is made for w or s
  492.        GOTO end
  493.        :dog
  494.        REM Next command starts word processor
  495.        WORD
  496.        GOTO end
  497.        :cat
  498.        REM Next command starts spreadsheet
  499.        LOTUS
  500.        GOTO end
  501.        :end
  502.        REM Next line switches to root directory/leave the batch file
  503.        CD\   
  504.        ECHO Batch file done, bye bye!
  505.  
  506.        ███ SHIFT ███  Re-assigns the relationship of parameters to 
  507.        markers. It changes their values. And it does it in a very odd 
  508.        way . . . 
  509.  
  510.        Remember that there are only ten markers available to a batch 
  511.        file to hold the parameter values as we mentioned above. Here 
  512.        they are: 
  513.  
  514.        %0    %1    %2    %3    %4    %5    %6    %7    %8    %9 
  515.  
  516.        However you can raise the limit of 10 parameters in a batch file 
  517.        using the single word SHIFT. When this command is encountered in 
  518.        a batch file, all the parameter and marker pairings are shifted 
  519.        one unit to the left. Whatever was assigned to %0 is lost. 
  520.  
  521.        A diagram to visualize. Before a SHIFT command is issued the 
  522.        parameters and markers might be: 
  523.  
  524.                 %0    %1    %2    
  525.                  |     |     |
  526.                 dog   cat    computer
  527.  
  528.        After the SHIFT command we would see:
  529.  
  530.                 %0    %1          %2    
  531.                  |     |          |
  532.                 cat   computer
  533.  
  534.        Notice that dog is lost, %1 becomes computer and %2 is left 
  535.        vacant unless it takes a new parameter from %3 (if %3 had a 
  536.        parameter). The effects of the SHIFT command are wide ranging 
  537.        throughout the batch file but provide great flexibility and a 
  538.        range of parameters greater than ten values. 
  539.  
  540.        ███ FOR..IN..DO ███    Allows iteration (repetition) of actions 
  541.        or commands. The command is similar to a FOR...NEXT...STEP loop 
  542.        programmers use. 
  543.  
  544.        The command is rather subtle and could be thought of as a three 
  545.        part single line command. The syntax is on the next line: 
  546.  
  547.        FOR %%Variable IN (Set) DO Command 
  548.  
  549.        Let's look more closely at the three parts: 
  550.  
  551.           FOR %%Variable       IN (Set)    DO Command
  552.           ==============       =======     ==========
  553.               |                    |           |         
  554.             part 1              part 2     part 3    
  555.  
  556.        Translating into english it means something like: FOR a certain 
  557.        batch file variable withIN a SET of filenames or commands DO a 
  558.        certain action which DOS can carry out. 
  559.  
  560.        The %%VARIABLE is a one-letter variable which must have a double 
  561.        %% prior to the letter to distinguish it from single % markers 
  562.        we have seen earlier. 
  563.  
  564.        The SET portion of the command is always in parenthesis as 
  565.        (SET). The SET represents filenames or DOS commands you wish the 
  566.        %% variable to assume while the command is executing. A space is 
  567.        used between entries. Pathnames are never allowed but wildcards 
  568.        such as *.* are acceptable. If the SET contains DOS command then 
  569.        only the %%VARIABLE is used. 
  570.               
  571.        The COMMAND is a DOS command or batch subcommand. One or several 
  572.        of these commands will contain the %%Variable in it. 
  573.  
  574.        Let's try an example. Pretend by you want a batch file to see 
  575.        the DOS version then clear the screen and finally issue the 
  576.        directory. We could do this with a three line batch file but 
  577.        FOR..IN..DO can do this in one: 
  578.  
  579.        Example:    FOR %%T IN (Ver cls Dir/P) DO %%T 
  580.  
  581.        Notice in the above example how each DOS command is separated by 
  582.        a space. ? and * are not allowed within any command within the 
  583.        SET. Use a colon (:) instead of a space within the set when 
  584.        passing parameters to programs. You can issue the FOR..IN..DO 
  585.        batch file subcommand at the DOS prompt by dropping one of the 
  586.        percentage signs ( % ) on the variable. 
  587.  
  588.        ████████████████████████████████████████████████████████████████ 
  589.  
  590.                       A BATCH FILE SUMMARY AND POP QUIZ! 
  591.  
  592.        ████████████████████████████████████████████████████████████████ 
  593.  
  594.        Use your imagination to construct batch files to shorten your 
  595.        DOS tasks. 
  596.  
  597.        Here is the source code text of GO.BAT which used to control 
  598.        the old version of PC-LEARN with a batch file menu!
  599.  
  600.        You could use a batch file such as this to operate a menu for 
  601.        your hard drive! By the way, for a lengthy batch file such as 
  602.        this, you would probably use your word processor to prepare the 
  603.        batch file rather than the tedious COPY CON command method used 
  604.        earlier - just make sure that the final file is output as pure 
  605.        ASCII text; see your word processor manual for notes on this 
  606.        technique. The basic flow of this long batch file is to display 
  607.        a menu screen, wait for a keypress for the user to select and 
  608.        then using a label system to branch to that area of the program 
  609.        that views or displays a test tutorial to the screen.
  610.  
  611.        Menu batch file for an older version of PC-LEARN:
  612.  
  613.  
  614.  
  615.    BATCH FILE COMMAND            EXPLANATION
  616.      |                               |
  617.    ECHO OFF           Cause screen NOT to display each batch file command
  618.    CLS                Clear screen from any previous program display
  619.    DRIVER1            Run driver1.com to display cover screen of PC-LEARN
  620.    PAUSE              Wait for keypress
  621.    :TOP               Label marker, serves as a "bookmark"
  622.    DRIVER2            Run driver2.com, diplay main menu
  623.    :START             Label marker, serves as a "bookmark"
  624.    DRIVER3            Run driver3.com, read keypress for menu selection  
  625.    ECHO ON            Turn on echo to display following comment . . .
  626.    REM  -----  WAIT FOR A MOMENT - DISK DRIVE LOADING DATA -----
  627.    ECHO OFF                 Turn echo back off to quench screen clutter
  628.    IF ERRORLEVEL 27 GOTO END      "errorlevel" line tests keypress
  629.    IF ERRORLEVEL 21 GOTO START     another errorlevel test                     
  630.    IF ERRORLEVEL 20 GOTO LABELT    another error level test         
  631.    IF ERRORLEVEL 19 GOTO LABELS                                          
  632.    IF ERRORLEVEL 18 GOTO LABELR                                          
  633.    IF ERRORLEVEL 17 GOTO LABELQ                                          
  634.    IF ERRORLEVEL 16 GOTO LABELP                                          
  635.    IF ERRORLEVEL 15 GOTO LABELO                                          
  636.    IF ERRORLEVEL 14 GOTO LABELN                                          
  637.    IF ERRORLEVEL 13 GOTO LABELM                                          
  638.    IF ERRORLEVEL 12 GOTO LABELL                                          
  639.    IF ERRORLEVEL 11 GOTO LABELK                                          
  640.    IF ERRORLEVEL 10 GOTO LABELJ                                          
  641.    IF ERRORLEVEL 9 GOTO LABELI                                           
  642.    IF ERRORLEVEL 8 GOTO LABELH
  643.    IF ERRORLEVEL 7 GOTO LABELG
  644.    IF ERRORLEVEL 6 GOTO LABELF
  645.    IF ERRORLEVEL 5 GOTO LABELE
  646.    IF ERRORLEVEL 4 GOTO LABELD
  647.    IF ERRORLEVEL 3 GOTO LABELC
  648.    IF ERRORLEVEL 2 GOTO LABELB
  649.    :LABELA                            Destination label if keypress is "A" 
  650.    view intro.tut                     Run view.com to display intro tutorial
  651.    GOTO TOP                           Goto label "top" when done
  652.    :LABELB                            Remaining lines similar to above
  653.    view history.tut
  654.    GOTO TOP
  655.    :LABELC
  656.    view dos1.tut
  657.    GOTO TOP
  658.    :LABELD
  659.    view dos2.tut
  660.    GOTO TOP
  661.    :LABELE
  662.    view batch.tut
  663.    GOTO TOP
  664.    :LABELF
  665.    view wordp.tut
  666.    GOTO TOP
  667.    :LABELG
  668.    view spread.tut
  669.    GOTO TOP
  670.    :LABELH
  671.    view databs.tut
  672.    GOTO TOP
  673.    :LABELI
  674.    view hd.tut
  675.    GOTO TOP
  676.    :LABELJ
  677.    view displstd.tut
  678.    GOTO TOP
  679.    :LABELK
  680.    view equipmnt.tut
  681.    GOTO TOP
  682.    :LABELL
  683.    view bibliog.tut
  684.    GOTO TOP
  685.    :LABELM
  686.    view usergrp.tut
  687.    GOTO TOP
  688.    :LABELN
  689.    view glossry.tut
  690.    GOTO TOP
  691.    :LABELO
  692.    view software.tut
  693.    GOTO TOP
  694.    :LABELP
  695.    view modem.tut
  696.    GOTO TOP
  697.    :LABELQ
  698.    view tips.tut
  699.    GOTO TOP
  700.    :LABELR
  701.    view virus.tut
  702.    GOTO TOP
  703.    :LABELS
  704.    view bonus.tut
  705.    GOTO TOP
  706.    :LABELT
  707.    view author.tut
  708.    GOTO TOP
  709.    :END
  710.    CLS
  711.    ECHO ON
  712.    REM   -----  THANKS FOR USING PC-LEARN! END OF TUTORIAL SYSTEM -----
  713.    REM   -----  REGISTERING PC-LEARN WILL BRING YOU THE BONUS DISK! ----
  714.    
  715.    (end of PC-LEARN batch file GO.BAT example)
  716.  
  717.